/**
 * @a https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/
 */

#include "common.h"

class Solution {
public:
    string removeDuplicates(string s) {
        string ret;
        for(auto ch : s){
            if(!ret.empty() && ret.back() == ch)
                ret.pop_back();// 出栈
            else
                ret.push_back(ch); // 入栈
        }
        return ret;
    }
};



class Solution {
public:
    string removeDuplicates(string s) {
        stack<char, list<char>> st;
        for(char ch : s){
            if(st.empty()) {
                st.push(ch);
                continue;
            }
            if(ch == st.top()){
                st.pop();
            }
            else {
                st.push(ch);
            }
        }
        string ret;
        while(!st.empty()){
            ret += st.top();
            st.pop();
        }
        reverse(ret.begin(),ret.end());
        return ret;
    }
};